<?php

namespace Sharks\Core\Support\FrontEnd;

use lessc;

/**
 * Less处理
 */
class LessHandler {

    public static function handle($sourceFilePath, $destAssetDir, $destFile) {

        if (AssetHandler::compareTime($sourceFilePath, $destAssetDir . '/' . $destFile->filename . '.' . $destFile->extension)) {
            try {
                if (!is_dir($destAssetDir)) {
                    mkdir($destAssetDir, 0700, true);
                }
                $less = new lessc();
                $less->compileFile($sourceFilePath, $destAssetDir . '/' . $destFile->filename . '.css');

                
            } catch (Exception $e) {
                Logging::logger(LessHandler::class)->debug($e->getMessage());
                throw new Exception($e);
            }
        }
    }
}